/*
 *  Copyright (c)  13.04.2007 Philipp Marx.
 *  Permission is granted to copy, distribute and/or modify this document
 *  under the terms of the GNU Free Documentation License, Version 1.2
 *  or any later version published by the Free Software Foundation;
 *  with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
 *  A copy of the license is included in the section entitled "GNU
 *  Free Documentation License".
 */
package de.smigfu.irc.handler;

/**
 * A message is a message in the sence of the IRC-RFC. It is wrapped inside this class for ease 
 * of use. It provides a mechansim to read the sender (if available), the command and the params
 * (if available). 
 *
 * @version $Revision$ $Date$
 *
 * @author Philipp Marx, last modified by $Author$
 */
public class Message {

   /** The command. */
   private String command;
   
   /** The original message. */
   private String message;
   
   /** The sender. */
   private String nickName;
   
   /** The params. */
   private String params;
   
   /** The prefix of the message. It may contain the sender in various styles. */
   private String prefix;

   /**
    * Constructs a <code>Message</code>.
    *
    * @param message The original message.
    */
   public Message(String message) {
      if(message == null) {
         throw new IllegalArgumentException("message must not be NULL!");
      }
      
      this.message = message;
      
      String[] parts = MessageProcessor.extractMessageParts(this.message);
      this.prefix = parts[0];
      this.command = parts[1].toUpperCase();
      this.params = parts[2];
      
      this.nickName = MessageProcessor.extractNickName(this.prefix);
   }

   /**
    * Returns the command. This is a 3-digit or a letter-only command. 
    * 
    * @return The command.
    */
   public String getCommand() {
      return this.command;
   }

   /**
    * Return the original message.
    *  
    * @return The original message.
    */
   public String getMessage() {
      return this.message;
   }

   /**
    * Returns the nickname or <code>null</code> if none is available.
    * 
    * @return The nickname or <code>null</code>
    */
   public String getNickName() {
      return this.nickName;
   }

   /**
    * Returns the parameters as a whole or <code>null</code> if none is available.
    * 
    * @return The parameters.
    */
   public String getParams() {
      return this.params;
   }
}
